﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using PkwHCFramework.Communications;

namespace PkwHCFramework.Models
{
    public class DataPoint : ObservableObject
    {
        private object _currentValue;

        public string PointNum { get; set; }

        public string PointDescription { get; set; }

        public string VarAddress { get; set; }

        public string VarType { get; set; }

        /// <summary>
        /// 是否开关量
        /// </summary>
        public bool IsOnOff { get; set; }

        public object CurrentValue
        {
            get { return _currentValue; }
            set { SetProperty(ref _currentValue, value); }
        }

        public RegisterPoint Model { get; set; }

        public DataPoint(RegisterPoint pointModel)
        {
            Model = pointModel;
            PointNum = pointModel.UID;
            PointDescription = pointModel.Name;
            VarAddress = pointModel.RegisterType + ":" + pointModel.Address;
            VarType = pointModel.Type.ToString();
            IsOnOff = pointModel.Type.FullName == "System.Boolean";
        }

        public void UpdateValue()
        {
            CurrentValue = Model.Value;
        }
    }
}
